package InterviewTest.q0103_replaceSpaces;

public class Solution_1 {
    public String replaceSpaces(String S, int length) {
        int p = 0;
        for (int i = 0; i < length; i++) {
            if (Character.isLetter(S.charAt(i))) p++;
        }

        char[] chars = new char[p + (length - p) * 3];
        p = 0;
        for (int i = 0; i < length; i++) {
            if (Character.isLetter(S.charAt(i))) {
                chars[p] = S.charAt(i);
                p++;
            }else {
                chars[p] = '%';
                chars[p + 1] = '2';
                chars[p + 2] = '0';
                p += 3;
            }

        }

        return new String(chars);
    }
}
